<template>
  <mt-header :title="title">
      <span slot="left">
        <mt-button @click="goBack" icon="back">返回</mt-button>
      </span>
    <mt-button @click="openWeChat" slot="right">
      <span class="iconfont icon-fenxiang"></span>
    </mt-button>
  </mt-header>
</template>

<script>
  import Vue from 'vue';
  import {Header, Button} from 'mint-ui';
  import {getWeChatUrl} from '../../axios/api';
  import share from 'm-share';
  // var wx = require('weixin-js-sdk');
  // import wx from 'weixin-js-sdk';

  Vue.component(Header.name, Header);
  Vue.component(Button.name, Button);
  export default {
    name: 'DetailsHeader',
    props: {
      title: {
        type: String
      }
    },
    computed: {
      getCircleOfFriendsTitle() {
        return this.$store.getters.getCircleOfFriendsTitle;
      },
    },
    methods: {
      goBack() {
        this.$router.go(-1)
      },
      openWeChat() {
        getWeChatUrl(location.href.split('#')[0]).then(res => {
          wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.data.appId, // 必填，公众号的唯一标识
            timestamp: res.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
            signature: res.data.signature, // 必填，签名
            jsApiList: [
              // 'onMenuShareAppMessage',
              'updateTimelineShareData'] // 此处填你所用到的方法
          });
          wx.ready(() => {
            let _this = this;
            wx.updateTimelineShareData({
              title: this.getCircleOfFriendsTitle, // 分享标题
              link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
              imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png' // 分享图标
            }, function(res) {
              //这里是回调函数
              _this.$router.push({name: 'Index'})

            });

          });
          share.wxConfig({
            title: this.getCircleOfFriendsTitle,
            link:window.location.href,
            desc: this.getCircleOfFriendsTitle,
            imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png',
            wx: {
              appId: res.data.appId, // 必填，公众号的唯一标识
              timestamp: res.data.timestamp, // 必填，生成签名的时间戳
              nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
              signature: res.data.signature // 必填，签名
            }
          });

          share.to('wxline', {
            title: this.getCircleOfFriendsTitle,
            link: window.location.href,
            desc: this.getCircleOfFriendsTitle,
            imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png',
            wx: {
              appId: res.data.appId, // 必填，公众号的唯一标识
              timestamp: res.data.timestamp, // 必填，生成签名的时间戳
              nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
              signature: res.data.signature // 必填，签名
            }
          });
        })
      }
    }
  }
</script>

<style scoped>
  .information_details .mint-header {
    background-color: #e6191e;

  }
</style>
